package org.example.platform.elasticsearch.service;

import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.ObjectUtil;
import org.example.platform.elasticsearch.entity.Hotel;
import org.springframework.stereotype.Service;

/**
 * 非空校验
 */
@Service
public class CommonService {


    /**
     * 校验非空
     * @param indexName
     * @return
     * @throws Exception
     */
    public String indexNameIsBlank(String indexName) throws Exception {
        if (CharSequenceUtil.isBlank(indexName)) {
            throw new Exception("索引名不能为空;");
        }
        return indexName;
    }

    /**
     * 校验非空
     * @param hotel
     * @return
     * @throws Exception
     */
    public Hotel hotelIsEmpty(Hotel hotel) throws Exception {
        if (ObjectUtil.isEmpty(hotel)) {
            throw new Exception("搜索条件不能为空;");
        }
        return hotel;
    }

    /**
     * 校验非空
     * @param propertiesName
     * @return
     * @throws Exception
     */
    public String propertiesNameIsBlank(String propertiesName) throws Exception {
        if (CharSequenceUtil.isBlank(propertiesName)) {
            throw new Exception("想要查询的字段名不能为空;");
        }
        return propertiesName;
    }
}
